﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
namespace 李晓霞web
{
    public partial class StudentScoreManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String strCn = "Server=pc.hstc.cn;database=dhd2014112106;uid=2014112106;pwd=19950616";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();

                if (ddlScore1.SelectedValue == "FirstScort")
                {
                    string strSql = "SELECT   学号,姓名,高等数学1,大学英语1,C语言,计算机导论,大学体育 From FirstScort WHERE   (学号= N'" + this.txtNo.Text + "')";

                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        this.lblCname1.Text = "高等数学1";
                        this.lblCname2.Text = "大学英语1";
                        this.lblCname3.Text = "C语言";
                        this.lblCname4.Text = "计算机导论";
                        this.lblCname5.Text = "大学体育";


                        this.txtCname1.Text = dr["高等数学1"].ToString();

                        this.txtCname2.Text = dr["大学英语1"].ToString();
                        this.txtCname3.Text = dr["C语言"].ToString();
                        this.txtCname4.Text = dr["计算机导论"].ToString();
                        this.txtCname5.Text = dr["大学体育"].ToString();
                    }
                }
                else
                {
                    if (ddlScore1.SelectedValue == "SecondScore")
                    {
                        string strSql = "SELECT   学号,姓名,高等数学2,大学英语2,静态网页,Java,大学体育  FROM SecondScore WHERE   (学号= N'" + this.txtNo.Text + "')";

                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            this.lblCname1.Text = "高等数学2";
                            this.lblCname2.Text = "大学英语2";
                            this.lblCname3.Text = "静态网页";
                            this.lblCname4.Text = "Java";
                            this.lblCname5.Text = "大学体育";

                            this.txtCname1.Text = dr["高等数学2"].ToString();
                            this.txtCname2.Text = dr["大学英语2"].ToString();
                            this.txtCname3.Text = dr["静态网页"].ToString();
                            this.txtCname4.Text = dr["Java"].ToString();
                            this.txtCname5.Text = dr["大学体育"].ToString();
                        }

                    }
                    else
                    {
                        if (ddlScore1.SelectedValue == "ThirdScore")
                        {
                            string strSql = "SELECT   学号,姓名,线性代数,大学英语3,数据结构,数据库,中国近代史 FROM ThirdScore WHERE   (学号= N'" + this.txtNo.Text + "')";
                            SqlCommand cmd = new SqlCommand(strSql, cn);
                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.Read())
                            {
                                this.lblCname1.Text = "线性代数";
                                this.lblCname2.Text = "大学英语3";
                                this.lblCname3.Text = "数据结构";
                                this.lblCname4.Text = "数据库";
                                this.lblCname5.Text = "中国近代史";


                                this.txtCname1.Text = dr["线性代数"].ToString();

                                this.txtCname2.Text = dr["大学英语3"].ToString();
                                this.txtCname3.Text = dr["数据结构"].ToString();
                                this.txtCname4.Text = dr["数据库"].ToString();
                                this.txtCname5.Text = dr["中国近代史"].ToString();

                            }
                        }
                        else
                        {
                            if (ddlScore1.SelectedValue == "FourthScore")
                            {
                                string strSql = "SELECT   学号,姓名,大学英语4,教育学,计算机网络,离散数学,uml FROM FourthScore  WHERE   (学号= N'" + this.txtNo.Text + "')";
                                SqlCommand cmd = new SqlCommand(strSql, cn);
                                SqlDataReader dr = cmd.ExecuteReader();
                                if (dr.Read())
                                {

                                    this.lblCname1.Text = "大学英语4";
                                    this.lblCname2.Text = "教育学";
                                    this.lblCname3.Text = "计算机网络";
                                    this.lblCname4.Text = "离散数学";
                                    this.lblCname5.Text = "uml";

                                    this.txtCname1.Text = dr["大学英语4"].ToString();

                                    this.txtCname2.Text = dr["教育学"].ToString();
                                    this.txtCname3.Text = dr["计算机网络"].ToString();
                                    this.txtCname4.Text = dr["离散数学"].ToString();
                                    this.txtCname5.Text = dr["uml"].ToString();
                                }
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void txtCname2_TextChanged(object sender, EventArgs e)
        {

        }

        protected void txtCname5_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            String strCn = "Server=pc.hstc.cn;database=dhd2014112106;uid=2014112106;pwd=19950616";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();

                if (ddlScore1.SelectedValue == "FirstScort")
                {
                    string strSql = "UPDATE FirstScort SET 高等数学1=N'" + this.txtCname1.Text + "',大学英语1=N'" + this.txtCname2.Text + "',C语言=N'" + this.txtCname3.Text + "',计算机导论=N'" + this.txtCname4.Text + "',大学体育=N'" + this.txtCname5.Text + "'WHERE (学号=N'" + this.txtNo.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        this.lblInfo.Text = "修改失败！";
                    }
                    else
                    {
                        this.lblInfo.Text = "修改了" + iUpd.ToString() + "条记录！";
                    }
                }
                else
                {
                    if (ddlScore1.SelectedValue == "SecondScore")
                    {
                        string strSql = "UPDATE SecondScore SET 高等数学2=N'" + this.txtCname1.Text + "',大学英语2=N'" + this.txtCname2.Text + "',静态网页=N'" + this.txtCname3.Text + "',Java=N'" + this.txtCname4.Text + "',大学体育=N'" + this.txtCname5.Text + "'WHERE (学号=N'" + this.txtNo.Text + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        int iUpd = cmd.ExecuteNonQuery();
                        if (iUpd < 1)
                        {
                            this.lblInfo.Text = "修改失败！";
                        }
                        else
                        {
                            this.lblInfo.Text = "修改了" + iUpd.ToString() + "条记录！";
                        }
                    }




                    else
                    {
                        if (ddlScore1.SelectedValue == "ThirdScore")
                        {
                            string strSql = "UPDATE ThirdScore SET 线性代数=N'" + this.txtCname1.Text + "',大学英语3=N'" + this.txtCname2.Text + "',数据结构=N'" + this.txtCname3.Text + "',数据库=N'" + this.txtCname4.Text + "',中国近代史=N'" + this.txtCname5.Text + "'WHERE (学号=N'" + this.txtNo.Text + "')";
                            SqlCommand cmd = new SqlCommand(strSql, cn);
                            int iUpd = cmd.ExecuteNonQuery();
                            if (iUpd < 1)
                            {
                                this.lblInfo.Text = "修改失败！";
                            }
                            else
                            {
                                this.lblInfo.Text = "修改了" + iUpd.ToString() + "条记录！";
                            }
                        }






                        else
                        {
                            if (ddlScore1.SelectedValue == "FourthScore")
                            {
                                string strSql = "UPDATE FourthScore SET 大学英语4=N'" + this.txtCname1.Text + "',教育学=N'" + this.txtCname2.Text + "',计算机网络=N'" + this.txtCname3.Text + "',离散数学=N'" + this.txtCname4.Text + "',uml=N'" + this.txtCname5.Text + "'WHERE (学号=N'" + this.txtNo.Text + "')";
                                SqlCommand cmd = new SqlCommand(strSql, cn);
                                int iUpd = cmd.ExecuteNonQuery();
                                if (iUpd < 1)
                                {
                                    this.lblInfo.Text = "修改失败！";
                                }
                                else
                                {
                                    this.lblInfo.Text = "修改了" + iUpd.ToString() + "条记录！";
                                }
                            }

                        }


                    }
                }
            }

            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
             }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
             String strCn = "Server=pc.hstc.cn;database=dhd2014112106;uid=2014112106;pwd=19950616";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();

                if (ddlScore1.SelectedValue == "FirstScort")
                {
                    string strSql = "INSERT INTO FirstScort( 高等数学1, 大学英语1,C语言,计算机导论,大学体育) VALUES   (N'" + this.txtCname1.Text + "',N'" + this.txtCname2.Text + "',N'" + this.txtCname3.Text + "',N'" + this.txtCname4.Text + "',N'" + this.txtCname5.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        this.lblInfo.Text = "不好意思，新增失败!";
                    }
                    else
                    {
                        this.lblInfo.Text = "感谢您新增成功!";
                    }
                }
                else
                {
                    if (ddlScore1.SelectedValue == "SecondScore")
                    {
                        string strSql = "INSERT INTO SecondScore( 高等数学2, 大学英语2,静态网页,Java,大学体育) VALUES   (N'" + this.txtCname1.Text + "',N'" + this.txtCname2.Text + "',N'" + this.txtCname3.Text + "',N'" + this.txtCname4.Text + "',N'" + this.txtCname5.Text + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        int iUpd = cmd.ExecuteNonQuery();
                        if (iUpd < 1)
                        {
                            this.lblInfo.Text = "不好意思，新增失败!";
                        }
                        else
                        {
                            this.lblInfo.Text = "感谢您新增成功!";
                        }
                    }




                    else
                    {
                        if (ddlScore1.SelectedValue == "ThirdScore")
                        {
                            string strSql = "INSERT INTO ThirdScore( 线性代数, 大学英语3,数据结构,数据库,中国近代史) VALUES   (N'" + this.txtCname1.Text + "',N'" + this.txtCname2.Text + "',N'" + this.txtCname3.Text + "',N'" + this.txtCname4.Text + "',N'" + this.txtCname5.Text + "')";
                            SqlCommand cmd = new SqlCommand(strSql, cn);
                            int iUpd = cmd.ExecuteNonQuery();
                            if (iUpd < 1)
                            {
                                this.lblInfo.Text = "不好意思，新增失败!";
                            }
                            else
                            {
                                this.lblInfo.Text = "感谢您新增成功!";
                            }
                        }






                        else
                        {
                            if (ddlScore1.SelectedValue == "FourthScore")
                            {
                                string strSql = "INSERT INTO FourthScore( 大学英语4, 教育学,计算机网络,离散数学,uml) VALUES   (N'" + this.txtCname1.Text + "',N'" + this.txtCname2.Text + "',N'" + this.txtCname3.Text + "',N'" + this.txtCname4.Text + "',N'" + this.txtCname5.Text + "')";
                                SqlCommand cmd = new SqlCommand(strSql, cn);
                                int iUpd = cmd.ExecuteNonQuery();
                                if (iUpd < 1)
                                {
                                    this.lblInfo.Text = "不好意思，新增失败!";
                                }
                                else
                                {
                                    this.lblInfo.Text = "感谢您新增成功!";
                                }
                            }

                        }


                    }
                }
            }

            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
             }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
             String strCn = "Server=pc.hstc.cn;database=dhd2014112106;uid=2014112106;pwd=19950616";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();

                if (ddlScore1.SelectedValue == "FirstScort")
                {
                    string strSql = "DELETE FROM FirstScort WHERE  (学号= N'" + this.txtNo.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iDelete = cmd.ExecuteNonQuery();
                    if (iDelete < 1)
                    {
                        this.lblInfo.Text = "不好意思，删除失败！";
                    }
                    else
                    {
                        this.lblInfo.Text = "恭喜您！删除了" + iDelete.ToString() + "条记录！";
                    }
                }
                else
                {
                    if (ddlScore1.SelectedValue == "SecondScore")
                    {
                        string strSql = "DELETE FROM SecondScore WHERE  (学号= N'" + this.txtNo.Text + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        int iDelete = cmd.ExecuteNonQuery();
                        if (iDelete < 1)
                        {
                            this.lblInfo.Text = "不好意思，删除失败！";
                        }
                        else
                        {
                            this.lblInfo.Text = "恭喜您！删除了" + iDelete.ToString() + "条记录！";
                        }
                    }




                    else
                    {
                        if (ddlScore1.SelectedValue == "ThirdScore")
                        {
                            string strSql = "DELETE FROM ThirdScore WHERE  (学号= N'" + this.txtNo.Text + "')";
                            SqlCommand cmd = new SqlCommand(strSql, cn);
                            int iDelete = cmd.ExecuteNonQuery();
                            if (iDelete < 1)
                            {
                                this.lblInfo.Text = "不好意思，删除失败！";
                            }
                            else
                            {
                                this.lblInfo.Text = "恭喜您！删除了" + iDelete.ToString() + "条记录！";
                            }
                        }






                        else
                        {
                            if (ddlScore1.SelectedValue == "FourthScore")
                            {
                                string strSql = "DELETE FROM FourthScore WHERE  (学号= N'" + this.txtNo.Text + "')";
                                SqlCommand cmd = new SqlCommand(strSql, cn);
                                int iDelete = cmd.ExecuteNonQuery();
                                if (iDelete < 1)
                                {
                                    this.lblInfo.Text = "不好意思，删除失败！";
                                }
                                else
                                {
                                    this.lblInfo.Text = "恭喜您！删除了" + iDelete.ToString() + "条记录！";
                                }
                            }

                        }


                    }
                }
            }

            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
             }

        protected void btnContral_Click(object sender, EventArgs e)
        {

        }

        }
        }
        
    

